const equipment = {
  state: {
    list: [], // 信息数组
    rowlist: {}, // 点击的行数信息
    btnNum: 0, // 按钮类型
    isShow: Boolean, // 弹框显示还是隐藏
    listnumber: 0, // 武器，防具，战车，伙伴，道具
    listname: ''
  },
  mutations: {
    // 数组
    SET_LIST(state, data) {
      state.list = data
    },
    // 单个信息
    SET_ROW_LIST(state, data) {
      state.rowlist = data
    },
    // 详情，编辑，删除
    SET_BTN_NUM(state, data) {
      state.btnNum = data
    },
    // 弹框是否显示
    SET_IS_SHOW(state, data) {
      state.isShow = data
    },
    // 武器，防具，伙伴，战车，道具
    SET_LIST_NUMBER(state, data) {
      state.listnumber = data
      switch (data) {
        case 0:
          state.listname = '武器'
          break
        case 1:
          state.listname = '防具'
          break
        case 2:
          state.listname = '战车'
          break
        case 3:
          state.listname = '伙伴'
          break
        default:
          state.listname = '道具'
      }
    },
    // 删除某一项
    removeItem(state, id) {
      // 根据id查找索引
      const i = state.list.findIndex(x => x.id === id)
      if (i !== -1) {
        state.list.splice(i, 1)
      }
    }
  },
  actions: {
    setList({ commit }, data) {
      commit('SET_LIST', data)
    },
    setRowlist({ commit }, data) {
      commit('SET_ROW_LIST', data)
    },
    setBtnNum({ commit }, data) {
      commit('SET_BTN_NUM', data)
    },
    setIsShow({ commit }, data) {
      commit('SET_IS_SHOW', data)
    },
    setListNumber({ commit }, data) {
      commit('SET_LIST_NUMBER', data)
    }
  }
}

export default equipment
